<?php
$pharmacy_id = $_SESSION['acc_id'];
$pid = 0;
$product_name = $product_type = $country_id = $price = $laboratory = $product_description = "";
if(isset($_GET['owner'])){
$sql = "SELECT tblproduct.*,tblproduct_in_pharmacy.* FROM tblproduct, tblproduct_in_pharmacy WHERE tblproduct.id=$id AND tblproduct.id=tblproduct_in_pharmacy.product_id AND tblproduct_in_pharmacy.pharmacy_id = $pharmacy_id";
echo '<form action="process.php?action=add" name="frmadd" id="frmadd" enctype="multipart/form-data" method="post">';
}else{
$sql = "SELECT * FROM tblproduct WHERE id=$id";	
}
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if(dbNumRows($result)){
extract($row);
}
?>
<script src='jquery.js' type="text/javascript"></script>
<script src='documentation.js' type="text/javascript"></script>
<style type="text/css">
#backgroundPopup{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:100%;  
width:100%;  
top:0;  
left:0;  
background:#000000;  
border:1px solid #cecece;  
z-index:1;  
}
#popuptext{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:400px;  
width:650px;  
background:#FFFFFF;  
border:2px solid #cecece;  
z-index:2;  
padding:12px;  
font-size:13px;  
overflow:scroll;
overflow-x:hidden;
} 
#popupCategory{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:400px;  
width:635px;  
background:#FFFFFF;  
border:2px solid #cecece;  
z-index:2;  
padding:12px; 
overflow:scroll;
overflow-x: hidden; 
} 
#popuptextClose{
font-size:14px;
line-height:14px;
right:6px;
top:4px;
position:absolute;
color:#6fa5fd;
font-weight:700;
display:block;
cursor:pointer;
}
#popupcateClose{
font-size:14px;
line-height:14px;
right:6px;
top:4px;
position:absolute;
color:#6fa5fd;
font-weight:700;
display:block;
cursor:pointer;
}
</style>
<link rel="stylesheet" type="text/css" href="../css/admin_style.css"/>
<script src="popup.js" type="text/javascript"></script>
<div class="row-fluid">
	<div class="box">
<div class="title">
Product
</div>
<table cellpadding="5" cellspacing="5" border="0" width="100%" height="100%"  id="tblAddExistPro">
<tbody>
	<tr>
    <td>Category</td>
    <td width="10">:</td>
    <td><a style="color:#00F; text-decoration:underline" href="#top" id="selectCate" onclick="return false;"><em>View Category</em></a>
    <div id="popupCategory">
    <a id="popupcateClose">Save</a><br />
    <?php
	include('category.php');
	?>
    </div>    
    </td>
    </tr>
	<tr>
    <td>Product Name</td>
    <td width="10">:</td>
    <td><strong><?php echo $product_name;?></strong>&nbsp;&nbsp;
    (    
    <a href="#" id="displaypopup" style="color:#03F;">View Description</a>
    <div id="popuptext">
    <a id="popuptextClose">X</a><br />
    <?php echo stripslashes($product_description);?>
    </div>
    )
    </td>
    </tr>  
    <tr>
    <td>Product Type</td>
    <td width="10">:</td>
    <td><?php echo $product_type?>
    </td>
    </tr> 
	<tr class="imageitem"> 
    <td valign="top">Images</td>
    <td width="10" valign="top">:</td>
    <td width="80%" align="left" style="padding-bottom:10px;">    
	<?php
	$sql_img = "SELECT * FROM tblimage WHERE product_id =".$id;
	$result_img = mysql_query($sql_img);
	if(dbNumRows($result_img)){
   	while( $row_img = mysql_fetch_assoc($result_img)){
		if($row_img['product_id'] !=""){
   ?>
   <div style="float:left;" class="div<?php echo $row_img['id'];?>">
    <img src="images/<?php echo $row_img['thumbnail'];?>" class="border" />
    </div>
    <?php
		}//end if
	}//end if
	}//end while
	?>
	</td>
</tr>    

    <tr class="<?php echo $pid?>">
    <td>Made In</td>
    <td width="10">:</td>
    <td>
    <select name="selectCountry[]" id="selectbox" style="width:270px;" class="selectCon1">
    <option value="">select country</option>
    <?php
	$sql_coun = "SELECT id,country_name FROM tblcountries";
	$result_coun = mysql_query($sql_coun);
	while($row_coun = mysql_fetch_assoc($result_coun)){
	?>
    <option value="<?php echo $row_coun['id']?>" <?php echo($row_coun['id']==$country_id)?' selected="selected"':''?>><?php echo $row_coun['country_name']?></option>
    <?php	
	}
	?>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    Price($) : <input type="text" name="newprice[]" style="width:80px;" value="<?php echo $price;?>" class="txtprice" />
    </td>
    </tr>
    <tr class="<?php echo $pid?>">
    <td>Laboratory</td>
    <td width="10">:</td>
    <td><input type="text" name="new_laboratory[]" value="<?php echo $laboratory?>" class="labor" />
    <input type="hidden" name="hidupdate[]" value="<?php echo $pid;?>" />
    </td>
    </tr>  
    <tr>
    <td></td>
    <td></td>
    <td><img src="<?php echo W_ROOT;?>/images/add_icon.jpg" border="0" /> 
        <a style="color:#00F; text-decoration:underline" href="#" id="clicktoadd"  onclick="addNewCountry($(this)); return false;"><em>Add another Country</em></a></td>
    </tr>    
    <tr>
    <td colspan="3" align="center" style="padding-top:30px; padding-bottom:20px;">
		<input class="btn btn-primary" type="button" name="btnsubmit" value="Save" onclick="checkexistform();" />&nbsp;&nbsp;&nbsp;
        <input class="btn btn-warning" type="button" value="Cancel" onclick="window.location.href='index.php'" />
        <input type="hidden" name="hidnewid" value="<?php echo $id;?>" />
    </td>
    </tr>
    </tbody>
</table>
<script type="text/javascript">
	var addCountryNewHtml = "<tr>" + $("#tblAddExistPro tr:eq(4)").html() + "</tr><tr>" + $("#tblAddExistPro tr:eq(5)").html() + "</tr>";
	function addNewCountry(aLink){
		aLink.parent().parent().before(addCountryNewHtml);
		$('.txtprice:last').val('');
		$('.labor:last').val('');
		$('.selectCon1:last').val('');
	}
</script>
<div id="backgroundPopup"></div>
	</div><!--<div class="box">-->
</div><!--<div class="row-fluid">--> 
<?php
if(isset($_GET['owner'])){
	echo '</form>';
}
?>